/*
 * This file is part of the Sx Framework Library.
 * 
 * Copyright (C) 2013 University of Colorado Denver
 * <min.choi@ucdenver.edu> <shane.transue@ucdenver.edu>
 * 
 * Permission is hereby granted, free of charge, to any person obtaining a copy 
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 
 * copies of the Software, and to permit persons to whom the Software is 
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in 
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
 * DEALINGS IN THE SOFTWARE.
 */
#include <sxDouble.h>
#include <limits>

Sx::Double::Double() {
	this->value = 0.0;
}

Sx::Double::Double(const Double& f) {
	this->value = f.value;
}

Sx::Double::Double(double value) {
	this->value = value;
}

Sx::Double::Double(float value) {
	this->value = static_cast<double>(value);
}

Sx::Double::Double(short value) {
	this->value = static_cast<double>(value);
}

Sx::Double::Double(int value) {
	this->value = static_cast<double>(value);
}

Sx::Double::Double(long value) {
	this->value = static_cast<double>(value);
}

Sx::Double::~Double() {}

void Sx::Double::set(double value) {
	this->value = value;
}

double Sx::Double::data() const {
	return this->value;
}

Sx::Double::operator double () const {
	return this->value;
}

Sx::Double Sx::Double::Max() {
	return std::numeric_limits<double>::max();
}

Sx::Double Sx::Double::Min() {
	return std::numeric_limits<double>::min();
}

Sx::Double Sx::Double::Infinity() {
	return std::numeric_limits<double>::infinity();
}

unsigned long Sx::Double::ToUnsignedLong(const Double& d) {
	return static_cast<unsigned long>(d.value);
}

Sx::Double Sx::Double::operator + (const Double& d) {
	return Double(this->value + d.value);
}

Sx::Double Sx::Double::operator + (double d) {
	return Double(this->value + d);
}

Sx::Double Sx::Double::operator - (const Double& d) {
	return Double(this->value - d.value);
}

Sx::Double Sx::Double::operator - (double d) {
	return Double(this->value - d);
}

Sx::Double Sx::Double::operator * (const Double& d) {
	return Double(this->value * d.value);
}

Sx::Double Sx::Double::operator * (double d) {
	return Double(this->value * d);
}

Sx::Double Sx::Double::operator / (const Double& d) {
	return Double(this->value / d.value);
}

Sx::Double Sx::Double::operator / (double d) {
	return Double(this->value / d);
}

void Sx::Double::operator += (const Double& d) {
	this->value += d.value;
}

void Sx::Double::operator += (double d) {
	this->value += d;
}

void Sx::Double::operator -= (const Double& d) {
	this->value -= d.value;
}

void Sx::Double::operator -= (double d) {
	this->value -= d;
}

void Sx::Double::operator *= (const Double& d) {
	this->value *= d.value;
}

void Sx::Double::operator *= (double d) {
	this->value *= d;
}

void Sx::Double::operator /= (const Double& d) {
	this->value /= d.value;
}

void Sx::Double::operator /= (double d) {
	this->value /= d;
}

void Sx::Double::operator = (const Double& d) {
	this->value = d.value;
}

void Sx::Double::operator = (double d) {
	this->value = d;
}

bool Sx::Double::operator == (const Double& d) {
	if ( this->value == d.value ) return true;
	else return false;
}

bool Sx::Double::operator != (const Double& d) {
	if ( this->value == d.value ) return false;
	else return true;
}

bool Sx::Double::operator == (double d) {
	if ( this->value == d ) return true;
	else return false;
}

bool Sx::Double::operator != (double d) {
	if ( this->value == d ) return false;
	else return true;
}

bool Sx::Double::operator <= (const Double& d) {
	if ( this->value <= d.value ) return true;
	else return false;
}

bool Sx::Double::operator <= (double d) {
	if ( this->value <= d ) return true;
	else return false;
}

bool Sx::Double::operator >= (const Double& d) {
	if ( this->value >= d.value ) return true;
	else return false;
}

bool Sx::Double::operator >= (double d) {
	if ( this->value >= d ) return true;
	else return false;
}

bool Sx::Double::operator < (const Double &d) {
	if ( this->value < d.value ) return true;
	else return false;
}

bool Sx::Double::operator < (double d) {
	if ( this->value < d ) return true;
	else return false;
}

bool Sx::Double::operator > (const Double &d) {
	if ( this->value > d.value ) return true;
	else return false;
}

bool Sx::Double::operator > (double d) {
	if ( this->value > d ) return true;
	else return false;
}

Sx::Double operator + (double v, const Sx::Double& d) {
	Sx::Double r(v);
	r += d;
	return r;
}

Sx::Double operator - (double v, const Sx::Double& d) {
	Sx::Double r(v);
	r -= d;
	return r;
}

Sx::Double operator * (double v, const Sx::Double& d) {
	Sx::Double r(v);
	r *= d;
	return r;
}

Sx::Double operator / (double v, const Sx::Double& d) {
	Sx::Double r(v);
	r /= d;
	return r;
}

std::ostream& operator << (std::ostream &out, const Sx::Double& d) {
	out << static_cast<double>(d);
	return out;
}
